// File system functions 

var DOSXObject = new ActiveXObject("Scripting.FileSystemObject");
//var DOSADObject  = new ActiveXObject("ADODB.Stream");

function dos_isdir(dirname) {
  return DOSXObject.FolderExists(dirname);
}


function dos_isfile(fname) {
  return DOSXObject.FileExists(dos_fullpath(fname));
}

function dos_rm(fname) {
  DOSXObject.DeleteFile(fname);
}

function dos_pwd() {
  return DOSXObject.GetAbsolutePathName("");
}

function dos_fullpath(fname) {
  return DOSXObject.GetAbsolutePathName(fname);
}

function dos_open(fname) {
  return DOSXObject.OpenTextFile(fname,1,false); //
}

function dos_dir(dir,ext) {
  var dirarray=new Array();  
  if(dos_isdir(dir)) {
    var FSo = new Enumerator(DOSXObject.GetFolder(dir).Files);
    // Getting all files in FSo object
    //alert("push ?"+dir+" ext "+ext);
    for (;!FSo.atEnd();FSo.moveNext()){
      var fname=FSo.item().name;      
      if(!ext || fname.substring(fname.length-4,fname.length)==ext) {
	dirarray.push(fname.substring(0,fname.length-4));	
      }
    }
    dirarray.sort();
  }
  return dirarray;
}

